Proper connect_port
[juce-lv2.git] / juce / source / extras / the jucer / src / model / paintelements / jucer_PaintElementRectangle.h
blobb381e7a586b3b6e629684fd33df3206282bcc178
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCER_PAINTELEMENTRECTANGLE_JUCEHEADER__
27 #define __JUCER_PAINTELEMENTRECTANGLE_JUCEHEADER__
29 #include "jucer_ColouredElement.h"
32 //==============================================================================
33 /**
35 class PaintElementRectangle : public ColouredElement
37 public:
38 //==============================================================================
39 PaintElementRectangle (PaintRoutine* owner)
40 : ColouredElement (owner, "Rectangle", true, false)
44 ~PaintElementRectangle()
48 const Rectangle<int> getCurrentBounds (const Rectangle<int>& parentArea) const
50 return PaintElement::getCurrentBounds (parentArea); // bypass the ColouredElement implementation
53 void setCurrentBounds (const Rectangle<int>& newBounds, const Rectangle<int>& parentArea, const bool undoable)
55 PaintElement::setCurrentBounds (newBounds, parentArea, undoable); // bypass the ColouredElement implementation
58 void draw (Graphics& g, const ComponentLayout* layout, const Rectangle<int>& parentArea)
60 Component parentComponent;
61 parentComponent.setBounds (parentArea);
63 fillType.setFillType (g, getDocument(), parentArea);
65 const Rectangle<int> r (position.getRectangle (parentArea, layout));
66 g.fillRect (r);
68 if (isStrokePresent)
70 strokeType.fill.setFillType (g, getDocument(), parentArea);
72 g.drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight(),
73 roundToInt (getStrokeType().stroke.getStrokeThickness()));
77 void getEditableProperties (Array <PropertyComponent*>& properties)
79 ColouredElement::getEditableProperties (properties);
81 properties.add (new ShapeToPathProperty (this));
84 void fillInGeneratedCode (GeneratedCode& code, String& paintMethodCode)
86 if (! fillType.isInvisible())
88 String x, y, w, h, s;
89 positionToCode (position, code.document->getComponentLayout(), x, y, w, h);
91 fillType.fillInGeneratedCode (code, paintMethodCode);
92 s << "g.fillRect (" << x << ", " << y << ", " << w << ", " << h << ");\n\n";
94 paintMethodCode += s;
97 if (isStrokePresent && ! strokeType.isInvisible())
99 String x, y, w, h, s;
100 positionToCode (position, code.document->getComponentLayout(), x, y, w, h);
102 strokeType.fill.fillInGeneratedCode (code, paintMethodCode);
103 s << "g.drawRect (" << x << ", " << y << ", " << w << ", " << h << ", "
104 << roundToInt (strokeType.stroke.getStrokeThickness()) << ");\n\n";
106 paintMethodCode += s;
110 static const char* getTagName() throw() { return "RECT"; }
112 XmlElement* createXml() const
114 XmlElement* e = new XmlElement (getTagName());
115 position.applyToXml (*e);
117 addColourAttributes (e);
119 return e;
122 bool loadFromXml (const XmlElement& xml)
124 if (xml.hasTagName (getTagName()))
126 position.restoreFromXml (xml, position);
127 loadColourAttributes (xml);
129 return true;
131 else
133 jassertfalse
134 return false;
138 void convertToPath()
140 const Rectangle<int> r (getCurrentAbsoluteBounds());
142 Path path;
143 path.addRectangle ((float) r.getX(), (float) r.getY(), (float) r.getWidth(), (float) r.getHeight());
145 convertToNewPathElement (path);
148 private:
149 class ShapeToPathProperty : public ButtonPropertyComponent
151 public:
152 ShapeToPathProperty (PaintElementRectangle* const element_)
153 : ButtonPropertyComponent ("path", false),
154 element (element_)
158 void buttonClicked()
160 element->convertToPath();
163 const String getButtonText() const
165 return "convert to a path";
168 private:
169 PaintElementRectangle* const element;
174 #endif // __JUCER_PAINTELEMENTRECTANGLE_JUCEHEADER__